<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - Lua 5.4.0-alpha - src/ldump.c</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">src</a> - ldump.c</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">Lua 5.4.0-alpha</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">124</td>
            <td class="headerCovTableEntry">129</td>
            <td class="headerCovTableEntryHi">96.1 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2019-06-13 19:44:19</td>
            <td></td>
          </tr>
          <tr>
            <td class="headerItem">Legend:</td>
            <td class="headerValueLeg">            Lines:
            <span class="coverLegendCov">hit</span>
            <span class="coverLegendNoCov">not hit</span>
</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : /*
<span class="lineNum">       2 </span>            : ** $Id: ldump.c $
<span class="lineNum">       3 </span>            : ** save precompiled Lua chunks
<span class="lineNum">       4 </span>            : ** See Copyright Notice in lua.h
<span class="lineNum">       5 </span>            : */
<span class="lineNum">       6 </span>            : 
<span class="lineNum">       7 </span>            : #define ldump_c
<span class="lineNum">       8 </span>            : #define LUA_CORE
<span class="lineNum">       9 </span>            : 
<span class="lineNum">      10 </span>            : #include &quot;lprefix.h&quot;
<span class="lineNum">      11 </span>            : 
<span class="lineNum">      12 </span>            : 
<span class="lineNum">      13 </span>            : #include &lt;stddef.h&gt;
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span>            : #include &quot;lua.h&quot;
<span class="lineNum">      16 </span>            : 
<span class="lineNum">      17 </span>            : #include &quot;lobject.h&quot;
<span class="lineNum">      18 </span>            : #include &quot;lstate.h&quot;
<span class="lineNum">      19 </span>            : #include &quot;lundump.h&quot;
<span class="lineNum">      20 </span>            : 
<span class="lineNum">      21 </span>            : 
<span class="lineNum">      22 </span>            : typedef struct {
<span class="lineNum">      23 </span>            :   lua_State *L;
<span class="lineNum">      24 </span>            :   lua_Writer writer;
<span class="lineNum">      25 </span>            :   void *data;
<span class="lineNum">      26 </span>            :   int strip;
<span class="lineNum">      27 </span>            :   int status;
<span class="lineNum">      28 </span>            : } DumpState;
<span class="lineNum">      29 </span>            : 
<span class="lineNum">      30 </span>            : 
<span class="lineNum">      31 </span>            : /*
<span class="lineNum">      32 </span>            : ** All high-level dumps go through DumpVector; you can change it to
<span class="lineNum">      33 </span>            : ** change the endianness of the result
<span class="lineNum">      34 </span>            : */
<span class="lineNum">      35 </span>            : #define DumpVector(v,n,D)       DumpBlock(v,(n)*sizeof((v)[0]),D)
<span class="lineNum">      36 </span>            : 
<span class="lineNum">      37 </span>            : #define DumpLiteral(s,D)        DumpBlock(s, sizeof(s) - sizeof(char), D)
<span class="lineNum">      38 </span>            : 
<span class="lineNum">      39 </span>            : 
<span class="lineNum">      40 </span><span class="lineCov">        588 : static void DumpBlock (const void *b, size_t size, DumpState *D) {</span>
<span class="lineNum">      41 </span><span class="lineCov">        588 :   if (D-&gt;status == 0 &amp;&amp; size &gt; 0) {</span>
<span class="lineNum">      42 </span>            :     lua_unlock(D-&gt;L);
<span class="lineNum">      43 </span><span class="lineCov">        584 :     D-&gt;status = (*D-&gt;writer)(D-&gt;L, b, size, D-&gt;data);</span>
<span class="lineNum">      44 </span>            :     lua_lock(D-&gt;L);
<span class="lineNum">      45 </span>            :   }
<span class="lineNum">      46 </span><span class="lineCov">        588 : }</span>
<span class="lineNum">      47 </span>            : 
<span class="lineNum">      48 </span>            : 
<span class="lineNum">      49 </span>            : #define DumpVar(x,D)            DumpVector(&amp;x,1,D)
<span class="lineNum">      50 </span>            : 
<span class="lineNum">      51 </span>            : 
<span class="lineNum">      52 </span><span class="lineCov">        178 : static void DumpByte (int y, DumpState *D) {</span>
<span class="lineNum">      53 </span><span class="lineCov">        178 :   lu_byte x = (lu_byte)y;</span>
<span class="lineNum">      54 </span><span class="lineCov">        178 :   DumpVar(x, D);</span>
<span class="lineNum">      55 </span><span class="lineCov">        178 : }</span>
<span class="lineNum">      56 </span>            : 
<span class="lineNum">      57 </span>            : 
<span class="lineNum">      58 </span>            : /* DumpInt Buff Size */
<span class="lineNum">      59 </span>            : #define DIBS    ((sizeof(size_t) * 8 / 7) + 1)
<span class="lineNum">      60 </span>            : 
<span class="lineNum">      61 </span><span class="lineCov">        261 : static void DumpSize (size_t x, DumpState *D) {</span>
<span class="lineNum">      62 </span>            :   lu_byte buff[DIBS];
<span class="lineNum">      63 </span><span class="lineCov">        261 :   int n = 0;</span>
<span class="lineNum">      64 </span>            :   do {
<span class="lineNum">      65 </span><span class="lineCov">        270 :     buff[DIBS - (++n)] = x &amp; 0x7f;  /* fill buffer in reverse order */</span>
<span class="lineNum">      66 </span><span class="lineCov">        270 :     x &gt;&gt;= 7;</span>
<span class="lineNum">      67 </span><span class="lineCov">        270 :   } while (x != 0);</span>
<span class="lineNum">      68 </span><span class="lineCov">        261 :   buff[DIBS - 1] |= 0x80;  /* mark last byte */</span>
<span class="lineNum">      69 </span><span class="lineCov">        261 :   DumpVector(buff + DIBS - n, n, D);</span>
<span class="lineNum">      70 </span><span class="lineCov">        261 : }</span>
<span class="lineNum">      71 </span>            : 
<span class="lineNum">      72 </span>            : 
<span class="lineNum">      73 </span><span class="lineCov">        175 : static void DumpInt (int x, DumpState *D) {</span>
<span class="lineNum">      74 </span><span class="lineCov">        175 :   DumpSize(x, D);</span>
<span class="lineNum">      75 </span><span class="lineCov">        175 : }</span>
<span class="lineNum">      76 </span>            : 
<span class="lineNum">      77 </span>            : 
<span class="lineNum">      78 </span><span class="lineCov">         12 : static void DumpNumber (lua_Number x, DumpState *D) {</span>
<span class="lineNum">      79 </span><span class="lineCov">         12 :   DumpVar(x, D);</span>
<span class="lineNum">      80 </span><span class="lineCov">         12 : }</span>
<span class="lineNum">      81 </span>            : 
<span class="lineNum">      82 </span>            : 
<span class="lineNum">      83 </span><span class="lineCov">         12 : static void DumpInteger (lua_Integer x, DumpState *D) {</span>
<span class="lineNum">      84 </span><span class="lineCov">         12 :   DumpVar(x, D);</span>
<span class="lineNum">      85 </span><span class="lineCov">         12 : }</span>
<span class="lineNum">      86 </span>            : 
<span class="lineNum">      87 </span>            : 
<span class="lineNum">      88 </span><span class="lineCov">         86 : static void DumpString (const TString *s, DumpState *D) {</span>
<span class="lineNum">      89 </span><span class="lineCov">         86 :   if (s == NULL)</span>
<span class="lineNum">      90 </span><span class="lineCov">          7 :     DumpSize(0, D);</span>
<span class="lineNum">      91 </span>            :   else {
<span class="lineNum">      92 </span><span class="lineCov">         79 :     size_t size = tsslen(s);</span>
<span class="lineNum">      93 </span><span class="lineCov">         79 :     const char *str = getstr(s);</span>
<span class="lineNum">      94 </span><span class="lineCov">         79 :     DumpSize(size + 1, D);</span>
<span class="lineNum">      95 </span><span class="lineCov">         79 :     DumpVector(str, size, D);</span>
<span class="lineNum">      96 </span>            :   }
<span class="lineNum">      97 </span><span class="lineCov">         86 : }</span>
<span class="lineNum">      98 </span>            : 
<span class="lineNum">      99 </span>            : 
<span class="lineNum">     100 </span><span class="lineCov">         14 : static void DumpCode (const Proto *f, DumpState *D) {</span>
<span class="lineNum">     101 </span><span class="lineCov">         14 :   DumpInt(f-&gt;sizecode, D);</span>
<span class="lineNum">     102 </span><span class="lineCov">         14 :   DumpVector(f-&gt;code, f-&gt;sizecode, D);</span>
<span class="lineNum">     103 </span><span class="lineCov">         14 : }</span>
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span>            : 
<span class="lineNum">     106 </span>            : static void DumpFunction(const Proto *f, TString *psource, DumpState *D);
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span><span class="lineCov">         14 : static void DumpConstants (const Proto *f, DumpState *D) {</span>
<span class="lineNum">     109 </span>            :   int i;
<span class="lineNum">     110 </span><span class="lineCov">         14 :   int n = f-&gt;sizek;</span>
<span class="lineNum">     111 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     112 </span><span class="lineCov">         67 :   for (i = 0; i &lt; n; i++) {</span>
<span class="lineNum">     113 </span><span class="lineCov">         53 :     const TValue *o = &amp;f-&gt;k[i];</span>
<span class="lineNum">     114 </span><span class="lineCov">         53 :     DumpByte(ttypetag(o), D);</span>
<span class="lineNum">     115 </span><span class="lineCov">         53 :     switch (ttypetag(o)) {</span>
<span class="lineNum">     116 </span><span class="lineCov">          3 :       case LUA_TNIL:</span>
<span class="lineNum">     117 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     118 </span><span class="lineNoCov">          0 :       case LUA_TBOOLEAN:</span>
<span class="lineNum">     119 </span><span class="lineNoCov">          0 :         DumpByte(bvalue(o), D);</span>
<span class="lineNum">     120 </span><span class="lineNoCov">          0 :         break;</span>
<span class="lineNum">     121 </span><span class="lineCov">          3 :       case LUA_TNUMFLT:</span>
<span class="lineNum">     122 </span><span class="lineCov">          3 :         DumpNumber(fltvalue(o), D);</span>
<span class="lineNum">     123 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     124 </span><span class="lineCov">          3 :       case LUA_TNUMINT:</span>
<span class="lineNum">     125 </span><span class="lineCov">          3 :         DumpInteger(ivalue(o), D);</span>
<span class="lineNum">     126 </span><span class="lineCov">          3 :         break;</span>
<span class="lineNum">     127 </span><span class="lineCov">         44 :       case LUA_TSHRSTR:</span>
<span class="lineNum">     128 </span>            :       case LUA_TLNGSTR:
<span class="lineNum">     129 </span><span class="lineCov">         44 :         DumpString(tsvalue(o), D);</span>
<span class="lineNum">     130 </span><span class="lineCov">         44 :         break;</span>
<span class="lineNum">     131 </span><span class="lineCov">         53 :       default: lua_assert(0);</span>
<span class="lineNum">     132 </span>            :     }
<span class="lineNum">     133 </span>            :   }
<span class="lineNum">     134 </span><span class="lineCov">         14 : }</span>
<span class="lineNum">     135 </span>            : 
<span class="lineNum">     136 </span>            : 
<span class="lineNum">     137 </span><span class="lineCov">         14 : static void DumpProtos (const Proto *f, DumpState *D) {</span>
<span class="lineNum">     138 </span>            :   int i;
<span class="lineNum">     139 </span><span class="lineCov">         14 :   int n = f-&gt;sizep;</span>
<span class="lineNum">     140 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     141 </span><span class="lineCov">         19 :   for (i = 0; i &lt; n; i++)</span>
<span class="lineNum">     142 </span><span class="lineCov">          5 :     DumpFunction(f-&gt;p[i], f-&gt;source, D);</span>
<span class="lineNum">     143 </span><span class="lineCov">         14 : }</span>
<span class="lineNum">     144 </span>            : 
<span class="lineNum">     145 </span>            : 
<span class="lineNum">     146 </span><span class="lineCov">         14 : static void DumpUpvalues (const Proto *f, DumpState *D) {</span>
<span class="lineNum">     147 </span><span class="lineCov">         14 :   int i, n = f-&gt;sizeupvalues;</span>
<span class="lineNum">     148 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     149 </span><span class="lineCov">         33 :   for (i = 0; i &lt; n; i++) {</span>
<span class="lineNum">     150 </span><span class="lineCov">         19 :     DumpByte(f-&gt;upvalues[i].instack, D);</span>
<span class="lineNum">     151 </span><span class="lineCov">         19 :     DumpByte(f-&gt;upvalues[i].idx, D);</span>
<span class="lineNum">     152 </span>            :   }
<span class="lineNum">     153 </span><span class="lineCov">         14 : }</span>
<span class="lineNum">     154 </span>            : 
<span class="lineNum">     155 </span>            : 
<span class="lineNum">     156 </span><span class="lineCov">         14 : static void DumpDebug (const Proto *f, DumpState *D) {</span>
<span class="lineNum">     157 </span>            :   int i, n;
<span class="lineNum">     158 </span><span class="lineCov">         14 :   n = (D-&gt;strip) ? 0 : f-&gt;sizelineinfo;</span>
<span class="lineNum">     159 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     160 </span><span class="lineCov">         14 :   DumpVector(f-&gt;lineinfo, n, D);</span>
<span class="lineNum">     161 </span><span class="lineCov">         14 :   n = (D-&gt;strip) ? 0 : f-&gt;sizeabslineinfo;</span>
<span class="lineNum">     162 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     163 </span><span class="lineCov">         14 :   for (i = 0; i &lt; n; i++) {</span>
<span class="lineNum">     164 </span><span class="lineNoCov">          0 :     DumpInt(f-&gt;abslineinfo[i].pc, D);</span>
<span class="lineNum">     165 </span><span class="lineNoCov">          0 :     DumpInt(f-&gt;abslineinfo[i].line, D);</span>
<span class="lineNum">     166 </span>            :   }
<span class="lineNum">     167 </span><span class="lineCov">         14 :   n = (D-&gt;strip) ? 0 : f-&gt;sizelocvars;</span>
<span class="lineNum">     168 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     169 </span><span class="lineCov">         27 :   for (i = 0; i &lt; n; i++) {</span>
<span class="lineNum">     170 </span><span class="lineCov">         13 :     DumpString(f-&gt;locvars[i].varname, D);</span>
<span class="lineNum">     171 </span><span class="lineCov">         13 :     DumpInt(f-&gt;locvars[i].startpc, D);</span>
<span class="lineNum">     172 </span><span class="lineCov">         13 :     DumpInt(f-&gt;locvars[i].endpc, D);</span>
<span class="lineNum">     173 </span>            :   }
<span class="lineNum">     174 </span><span class="lineCov">         14 :   n = (D-&gt;strip) ? 0 : f-&gt;sizeupvalues;</span>
<span class="lineNum">     175 </span><span class="lineCov">         14 :   DumpInt(n, D);</span>
<span class="lineNum">     176 </span><span class="lineCov">         29 :   for (i = 0; i &lt; n; i++)</span>
<span class="lineNum">     177 </span><span class="lineCov">         15 :     DumpString(f-&gt;upvalues[i].name, D);</span>
<span class="lineNum">     178 </span><span class="lineCov">         14 : }</span>
<span class="lineNum">     179 </span>            : 
<span class="lineNum">     180 </span>            : 
<span class="lineNum">     181 </span><span class="lineCov">         14 : static void DumpFunction (const Proto *f, TString *psource, DumpState *D) {</span>
<span class="lineNum">     182 </span><span class="lineCov">         14 :   if (D-&gt;strip || f-&gt;source == psource)</span>
<span class="lineNum">     183 </span><span class="lineCov">          7 :     DumpString(NULL, D);  /* no debug info or same source as its parent */</span>
<span class="lineNum">     184 </span>            :   else
<span class="lineNum">     185 </span><span class="lineCov">          7 :     DumpString(f-&gt;source, D);</span>
<span class="lineNum">     186 </span><span class="lineCov">         14 :   DumpInt(f-&gt;linedefined, D);</span>
<span class="lineNum">     187 </span><span class="lineCov">         14 :   DumpInt(f-&gt;lastlinedefined, D);</span>
<span class="lineNum">     188 </span><span class="lineCov">         14 :   DumpByte(f-&gt;numparams, D);</span>
<span class="lineNum">     189 </span><span class="lineCov">         14 :   DumpByte(f-&gt;is_vararg, D);</span>
<span class="lineNum">     190 </span><span class="lineCov">         14 :   DumpByte(f-&gt;maxstacksize, D);</span>
<span class="lineNum">     191 </span><span class="lineCov">         14 :   DumpCode(f, D);</span>
<span class="lineNum">     192 </span><span class="lineCov">         14 :   DumpConstants(f, D);</span>
<span class="lineNum">     193 </span><span class="lineCov">         14 :   DumpUpvalues(f, D);</span>
<span class="lineNum">     194 </span><span class="lineCov">         14 :   DumpProtos(f, D);</span>
<span class="lineNum">     195 </span><span class="lineCov">         14 :   DumpDebug(f, D);</span>
<span class="lineNum">     196 </span><span class="lineCov">         14 : }</span>
<span class="lineNum">     197 </span>            : 
<span class="lineNum">     198 </span>            : 
<span class="lineNum">     199 </span><span class="lineCov">          9 : static void DumpHeader (DumpState *D) {</span>
<span class="lineNum">     200 </span><span class="lineCov">          9 :   DumpLiteral(LUA_SIGNATURE, D);</span>
<span class="lineNum">     201 </span><span class="lineCov">          9 :   DumpInt(LUAC_VERSION, D);</span>
<span class="lineNum">     202 </span><span class="lineCov">          9 :   DumpByte(LUAC_FORMAT, D);</span>
<span class="lineNum">     203 </span><span class="lineCov">          9 :   DumpLiteral(LUAC_DATA, D);</span>
<span class="lineNum">     204 </span><span class="lineCov">          9 :   DumpByte(sizeof(Instruction), D);</span>
<span class="lineNum">     205 </span><span class="lineCov">          9 :   DumpByte(sizeof(lua_Integer), D);</span>
<span class="lineNum">     206 </span><span class="lineCov">          9 :   DumpByte(sizeof(lua_Number), D);</span>
<span class="lineNum">     207 </span><span class="lineCov">          9 :   DumpInteger(LUAC_INT, D);</span>
<span class="lineNum">     208 </span><span class="lineCov">          9 :   DumpNumber(LUAC_NUM, D);</span>
<span class="lineNum">     209 </span><span class="lineCov">          9 : }</span>
<span class="lineNum">     210 </span>            : 
<span class="lineNum">     211 </span>            : 
<span class="lineNum">     212 </span>            : /*
<span class="lineNum">     213 </span>            : ** dump Lua function as precompiled chunk
<span class="lineNum">     214 </span>            : */
<span class="lineNum">     215 </span><span class="lineCov">          9 : int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,</span>
<span class="lineNum">     216 </span>            :               int strip) {
<span class="lineNum">     217 </span>            :   DumpState D;
<span class="lineNum">     218 </span><span class="lineCov">          9 :   D.L = L;</span>
<span class="lineNum">     219 </span><span class="lineCov">          9 :   D.writer = w;</span>
<span class="lineNum">     220 </span><span class="lineCov">          9 :   D.data = data;</span>
<span class="lineNum">     221 </span><span class="lineCov">          9 :   D.strip = strip;</span>
<span class="lineNum">     222 </span><span class="lineCov">          9 :   D.status = 0;</span>
<span class="lineNum">     223 </span><span class="lineCov">          9 :   DumpHeader(&amp;D);</span>
<span class="lineNum">     224 </span><span class="lineCov">          9 :   DumpByte(f-&gt;sizeupvalues, &amp;D);</span>
<span class="lineNum">     225 </span><span class="lineCov">          9 :   DumpFunction(f, NULL, &amp;D);</span>
<span class="lineNum">     226 </span><span class="lineCov">          9 :   return D.status;</span>
<span class="lineNum">     227 </span>            : }
<span class="lineNum">     228 </span>            : 
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
